package com.baozun.util;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 * 
 * @Title:
 * @Company:宝尊电子商务有限公司
 * @Author:万世极缘
 * @Since:2014-12-28
 * @Copyright:Copyright (c) 2014
 * @ModifyDate:2014-12-28
 * @Version:1.1.0
 */
public class MapUtil {
    
    public static String toString(Map<String, Object> map) {
        StringBuffer sb = new StringBuffer();
        Set<Entry<String, Object>> set = map.entrySet();
        Iterator<Entry<String, Object>> ite = set.iterator();
        while (ite.hasNext()) {
            Entry<String, Object> entry = ite.next();
            Object obj = entry.getValue();
            if (obj instanceof Map) {
                @SuppressWarnings("unchecked")
                Map<String, Object> childMap = (Map<String, Object>) obj;
                sb.append(toString(childMap));
            }
            sb.append(entry.getKey());
            sb.append(":");
            sb.append(entry.getValue());
            sb.append("\n");
        }
        return sb.toString();
    }
    
    public static String map2String(Map<String, String[]> parameterMap) {
        // TODO Auto-generated method stub
        StringBuffer sb = new StringBuffer();
        Set<Entry<String, String[]>> set = parameterMap.entrySet();
        Iterator<Entry<String, String[]>> ite = set.iterator();
        while (ite.hasNext()) {
            Entry<String, String[]> entry = ite.next();
            sb.append(entry.getKey());
            sb.append(":");
            String[] strArray = entry.getValue();
            sb.append("{");
            for (String str : strArray) {
                sb.append(str);
            }
            sb.append("}");
            sb.append("\n");
        }
        return sb.toString();
    }
}
